package Lee_code;

import java.util.Arrays;
import java.util.List;

public class Lee_139 {
    public boolean wordBreak(String s, List<String> wordDict) {

        boolean[] dp = new boolean[s.length() + 1];
        dp[0] = true;
        int string_num = wordDict.size();

        for(int i = 1; i <= s.length(); i++) {
            for (int j = 0; j < string_num; j++) {
                String temp = wordDict.get(j);
                if(temp.length()<=i)
                {
                    String sub = s.substring(i-temp.length(), i);
                    dp[i] = dp[i]||(dp[i-temp.length()] && sub.equals(temp));
                }
            }
        }
        return dp[s.length()];
    }
}
